<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport"/>
    <meta content="telephone=no" name="format-detection"/>
    <meta content="email=no" name="format-detection"/>
    <title>imgLoader</title>
    <style>
        *{
            padding: 0;
            margin: 0;
        }
        img{
            width: 100%;
            background: #BDBDBD url("img/img_placeholder.png") center no-repeat;
            background-size: 50%,auto;
        }
    </style>
</head>
<body>
<img height="200px" src="https://timgshtmleaf.com%2F1507%2F201507141843.jpg" onerror="imgLoadError()" onload="imgOnload()">
<div></div>
</body>
<script>
    window.onload = function () {
        console.log('onload');
    };
    function imgLoadError() {
        console.log('imgLoadError');
        var img = event.srcElement;
        img.src = "img/img_empty.png";
        img.onerror = null;
        img.onload = null;//防止失败了走 imgOnload()方法
    }
    function imgOnload() {
        console.log('imgOnload');
        var img = event.srcElement;
        img.setAttribute("height","auto");
        img.onload = null;
    }
</script>
</html>